package com.bilibili.juc.volatileList;

/**
 * @author zuife
 * @description
 * @since 2024-05-02 07:50:46
 */
public class SafeDoubleCheckSingleton {
    private volatile static  SafeDoubleCheckSingleton instance;
    private SafeDoubleCheckSingleton()
    {
    }
    public static SafeDoubleCheckSingleton getInstance()
    {
        if (instance == null)
        {
            //1.多线程并发，可能会创建多个实例，会通过加锁保证只有一个线程能创建对象
            synchronized (SafeDoubleCheckSingleton.class)
            {
                if (instance == null)
                {
                    instance = new SafeDoubleCheckSingleton();
                }
            }
        }
        return instance;
    }
}
